// pages/product/product_list.js
const app = getApp()
import {
  GoodsModels
} from "../../utils/models/goods/Goods-models";
var model = new GoodsModels();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navbarHeight: app.globalData.navbarHeight,
    titleName: '',
    isLeft: true,
    isHeight:false,
    navBgColor: "white",
    height:'',
    desc:'',
    page:1,
    cid:0,
    goodsList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      height: wx.getSystemInfoSync().windowHeight,
    })
    if(options.title) {
      this.setData({
        titleName : options.title
      });
    }
    if(options.desc){
      this.setData({
        'desc':options.desc
      })
    }
    if(options.cid){
      this.setData({
        'cid':options.cid,
        'page':1
      })
      var args = {
        'cid': options.cid,
        'page': 1
      }
      this.getGoodsList(args)
    }
  },
  isBottom() {
    let page = this.data.page;
    let cid = this.data.cid;
    page = page+1;
    this.getGoodsList({'cid':cid,'page':page});
    this.setData({
      page:page
    })
  },
  getGoodsList: function (args) {
    let that = this;
    let goodsList = this.data.goodsList;
    model.getGoodsList(args, function (res) {
      if (res.code > 0) {
        for (var i in res.data) {
          goodsList.push(res.data[i]);
        }
      }
      console.log(goodsList);
      that.setData({
        'goodsList': goodsList
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})